package com.cicigodd.brick.plug.security.resource.controller;

import com.cicigodd.brick.plug.annotation.resource.DeleteResource;
import com.cicigodd.brick.plug.annotation.resource.GetResource;
import com.cicigodd.brick.plug.annotation.resource.PostResource;
import com.cicigodd.brick.plug.annotation.resource.PutResource;
import com.cicigodd.brick.plug.common.response.PageResult;
import com.cicigodd.brick.plug.common.response.Result;
import com.cicigodd.brick.plug.common.response.ResultGenerator;
import com.cicigodd.brick.plug.security.resource.request.*;
import com.cicigodd.brick.plug.security.resource.response.SysResourceDetailResponse;
import com.cicigodd.brick.plug.security.resource.response.SysResourceListResponse;
import com.cicigodd.brick.plug.security.resource.service.SysResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@Api(tags = "系统资源")
@RestController
public class SysResourceController {

    @Resource
    private SysResourceService sysResourceService;


    @ApiOperation(value = "系统资源添加", notes = "系统资源添加")
    @PostResource(name = "系统资源添加", path = "/sysResource/add")
    public Result add(@RequestBody @Validated SysResourceAddRequest sysResourceAddRequest) {
        sysResourceService.add(sysResourceAddRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "系统资源删除", notes = "根据id删除")
    @DeleteResource(name = "系统资源删除", path = "/sysResource/delete")
    public Result delete(@Validated SysResourceDeleteRequest sysResourceDeleteRequest) {
        sysResourceService.delete(sysResourceDeleteRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "系统资源编辑", notes = "系统资源编辑")
    @PutResource(name = "系统资源编辑", path = "/sysResource/edit")
    public Result edit(@RequestBody @Validated SysResourceEditRequest sysResourceEditRequest) {
        sysResourceService.edit(sysResourceEditRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "系统资源详情", notes = "根据id查询")
    @GetResource(name = "系统资源详情", path = "/sysResource/detail")
    public Result<SysResourceDetailResponse> detail(SysResourceDetailRequest sysResourceDetailRequest) {
        SysResourceDetailResponse detail = sysResourceService.detail(sysResourceDetailRequest);
        return ResultGenerator.successResult(detail);
    }


    @ApiOperation(value = "系统资源分页列表", notes = "系统资源分页列表")
    @GetResource(name = "系统资源分页列表", path = "/sysResource/list")
    public Result<PageResult<SysResourceListResponse>> list(SysResourceListRequest sysResourceListRequest) {
        PageResult<SysResourceListResponse> pageList =  sysResourceService.list(sysResourceListRequest);
        return ResultGenerator.successResult(pageList);
    }
}
